package com.livepan.${MODULE}.controller;

import com.livepan.server.BaseController;
import com.livepan.server.error.BusinessException;
import com.livepan.server.response.CommonReturnType;
import com.livepan.server.service.${Domain}Service;
import com.livepan.server.service.model.${Domain}Model;
import com.livepan.server.service.model.PageModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/${domain}")
public class ${Domain}Controller extends BaseController {

    public static final String BUSINESS_NAME="${tableNameCn}";

    private static final Logger LOG = LoggerFactory.getLogger(${Domain}Controller.class);

    @Autowired
    private ${Domain}Service ${domain}Service;

    @ResponseBody
    @RequestMapping("/list")
    public CommonReturnType ${domain}(PageModel pageModel) {
        LOG.info("page:" + pageModel.getPage());
        ${domain}Service.list(pageModel);
        return CommonReturnType.create(pageModel);
    }

    @ResponseBody
    @RequestMapping("/save")
    public CommonReturnType save${Domain}(@RequestBody ${Domain}Model ${domain}Model) throws BusinessException {
        ${domain}Service.save(${domain}Model);
        return CommonReturnType.create(${domain}Model);
    }

    @ResponseBody
    @RequestMapping("/delete/{id}")
    public CommonReturnType delete(@PathVariable String id) {
        ${domain}Service.delete(id);
        return CommonReturnType.create(null);
    }
}
